<?php

/**
 * Blog plugin
 * Can post, edit, delete blogposts
 * @version $Id$
 * @copyright 2010
 */
class Blog extends Plugin
{
	public $plugin_name = "Blog";
	public $plugin_short_desc = "Blogging system";
	public $plugin_long_desc = "Blogging system allows user to add/edit/delete blogposts";
	public $version = "1.0";
	public $has_sidebar = true;
	public $has_footer = true;
	public $needs_install = true;

	/**
	 * Constructor
	 */
	function __construct()
	{
		global $theme, $db;
		$theme->set_title('Blog');
		$this->db = $db;

		// template with blogpost loop
		define('FILE_BLOGPOST_THEME', 'blogpost.html');

		// template with full article view
		define('FILE_ARTICLE_THEME', 'article.html');

		// template with comment loop
		define('FILE_COMMENT_THEME', 'comment.html');
	}

	/**
	 * Blog::generate_sidebar()
	 * Generates list of categories
	 * @return
	 */
	public function generate_sidebar()
	{
		global $theme;
		global $core;

		$out = '<ul>';

		$query = mysql_query("SELECT * FROM ".DB_PREFIX."yaps_blog_category ORDER BY name ASC");
		if(mysql_num_rows($query) > 0)
		{
			while($cat = mysql_fetch_array($query))
			{
				if($core->router_id == $cat['id'])
				{
					$out .= '<li>&raquo;&nbsp;<a href="blog-category-'.$cat['id'].'-'.$core->encode_url($cat['name']).'">'.$cat['name'].'</a></li>';
				}
				else
				{
					$out .= '<li><a href="blog-category-'.$cat['id'].'-'.$core->encode_url($cat['name']).'">'.$cat['name'].'</a></li>';
				}

			}
		}

		$out .= '</ul>';

		$theme->assign('sidebar',$out);
	}

	public function generate_footer()
	{
		global $theme;

		$query = mysql_query("SELECT * FROM ".DB_PREFIX."yaps_blog WHERE sandboxed = 0 ORDER BY published DESC LIMIT 0,5");
		if(mysql_num_rows($query) > 0)
		{
			$out = '<h1>Newest articles</h1>
							<ul>';
			while($article = mysql_fetch_array($query))
			{
				$out .= '<li>&raquo;&nbsp;<a href="'.$this->generate_article_link($article['id']).'">'.$article['title'].'</a></li>';
			}
		}
		$out .= '</ul>';

		$theme->assign('footer',$out);

	}

	/**
	 * Blog::start()
	 * Default function, display newest articles
	 * @return
	 */
	public function start()
	{
		//show all articles ordered by time DESC
		global $theme;
		$theme->include_jquery();

		//statistika
		$firmy = $this->db->get_object('SELECT COUNT(id) AS count FROM firma');
		$expozice = $this->db->get_object('SELECT COUNT(id) AS count FROM expozice');
		$exponat = $this->db->get_object('SELECT COUNT(id) AS count FROM exponat');
		$zam = $this->db->get_object('SELECT COUNT(id) AS count FROM zamestnanec');
		$stanek = $this->db->get_object('SELECT COUNT(id) AS count FROM stanek');
		$pavilon = $this->db->get_object('SELECT COUNT(id) AS count FROM pavilon');
		echo '<div>Dobry den, na vystavisti mame celkem <b>'.$firmy->count.'</b> vystavovatelu s <b>'.$expozice->count.'</b> expozicemi, ve kterych je celkem <b>'.$exponat->count.'</b> exponatu. Na vystavisti se o vas stara celkem <b>'.$zam->count.'</b> zamestnancu u <b>'.$stanek->count.'</b> stanku v <b>'.$pavilon->count.'</b> pavilonech.</div><br />';

		$this->show_category(true);
	}

	private function do_admin_forms()
	{
		global $core,$theme;

		//ADDING NEW BLOGPOST
		if($core->post('blogpost_text') && !$core->post('article_id'))
		{
			$hl = $core->load_plugin('highlight');

			$text = $core->post('blogpost_text');

			$text = preg_replace("(\[code=(.+?)\](.+?)\[\/code\])is","<pre class=\\\"sh_$1\\\">$2</pre>",$text);

			$query = 'INSERT INTO '.DB_PREFIX.'yaps_blog VALUES ("0",
			"'.$core->post_hsc('blogpost_title').'",
			"'.$core->post('blogpost_short').'",
			"'.$text.'",
			"'.$core->post_hsc('blogpost_category').'",
			NOW(),
			1)';
			$result = mysql_query($query);
			$id = mysql_insert_id();

			if($core->is_plugin('twitter') && $core->post('tweet_me'))
			{
				$twitter = $core->load_plugin('twitter');
				$twitter->tweet($core->post('blogpost_title'),$this->generate_article_link($id));
			}

			if($result) $core->msg('Blogpost has been successfuly added!');
			else $core->err('An error occured when adding a new blogpost. Check your DB table <b>yaps_blog</b>.<p>'.$query.'</p><p>'.mysql_error().'</p>');

			$theme->include_jquery();
			$theme->js('$(location).attr(\'href\',\'admin-pluginsettings?plugin=blog\');');
		}
		elseif($core->post('blogpost_text') && $core->post('article_id'))
		{
			$text = $core->post('blogpost_text');
			$text = preg_replace("(\[code=(.+?)\](.+?)\[\/code\])is","<pre class=\\\"sh_$1\\\">$2</pre>",$text);

			$query = "UPDATE ".DB_PREFIX."yaps_blog SET
			title = '".$core->post('blogpost_title')."',
			short_text = '".$core->post('blogpost_short')."',
			text = '".$text."',
			category = '".$core->post('blogpost_category')."'
			WHERE id = ".$core->post('article_id');
			$result = mysql_query($query);

			if($result) $core->msg('Blogpost has been successfuly edited!');
			else $core->err('An error occured when editing blogpost. Check your DB table <b>yaps_blog</b>.');

			$theme->include_jquery();
			$theme->js('$(location).attr(\'href\',\'admin-pluginsettings?plugin=blog\');');
		}
	}

	private function do_get_actions()
	{
		global $core,$theme;

		if($core->get('action') == 'switch_sandbox')
		{
			$query = mysql_query("UPDATE ".DB_PREFIX."yaps_blog SET sandboxed = ".$core->get('state')." WHERE id = ".$core->get('id'));
			if($query) $core->msg('Article has been successfuly published or moved to sandbox');
			else $core->err('Cannot move article in/out sandbox, look if article with id '.$core->get('id').' really exists in yaps_blox table in your DB.');

			$theme->include_jquery();
			$theme->js('$(location).attr(\'href\',\'admin-pluginsettings?plugin=blog\');');
		}
		elseif($core->get('action') == 'edit_article')
		{
			$query = mysql_query("SELECT * FROM ".DB_PREFIX."yaps_blog WHERE id = ".$core->get('id'));
			if(mysql_num_rows($query) > 0)
			{
				$article = mysql_fetch_array($query);

				$text = preg_replace("(<pre class=\"sh_(.+?)\">(.+?)<\/pre>)is","[code=$1]$2[/code]",$article['text']);

				echo '
				<h3>-Edit article ',$article['title'],'</h3>
			  <div>
				<form action="" method="post">
					<table border="0">
						<tr><td>Title</td><td><input type="text" name="blogpost_title" size="98" value="',stripslashes($article['title']),'" /></td></tr>
						<tr><td>Short text for article list</td><td><textarea name="blogpost_short" rows="5" cols="83" class="blogpost">',stripslashes($article['short_text']),'</textarea></td></tr>
						<tr><td>Article text</td><td><textarea name="blogpost_text" id="blogpost_text" rows="20" cols="84" class="blogpost">',stripslashes($text),'</textarea></td></tr>
						<tr><td>Category</td><td><select name="blogpost_category">';

							$query = mysql_query("SELECT * FROM ".DB_PREFIX."yaps_blog_category ORDER BY name ASC");
							while($cat = mysql_fetch_array($query))
							{
								echo '<option value="',$cat['id'],'" ',($cat['id'] == $article['category']) ? 'selected="true"' : '','>',$cat['name'],'</option>';
							}

							echo '</select></td></tr>
						<tr><td colspan="2"><input type="submit" value="Edit this article" />
						<input type="hidden" name="article_id" value="',$article['id'],'" /></td></tr>
					</table>
				</form>
				</div>';
			}
			else
			{
				$core->err('Bad article ID, check if your yaps_blog table containts row with ID '.$core->get('id'));
			}
		}
		elseif($core->get('action') == 'delete_article')
		{
			$query = mysql_query("DELETE FROM ".DB_PREFIX."yaps_blog WHERE id = ".$core->get('id'));
			$query_comments = mysql_query("DELETE FROM ".DB_PREFIX."yaps_blog_comments WHERE article = ".$core->get('id'));

			if($query && $query_comments) $core->msg('Article has been successfuly deleted with its comments');
			else $core->err('Cannot delete article, look if article with id '.$core->get('id').' really exists in yaps_blox table in your DB.');

			$theme->include_jquery();
			$theme->js('$(location).attr(\'href\',\'admin-pluginsettings?plugin=blog\');');
		}
	}

	/**
	 * Blog::admin_settings()
	 * Admin settings for admin plugin
	 * @return
	 */
	public function admin_settings()
	{
		global $core,$theme;

		$this->do_admin_forms(); //do forms requests
		$this->do_get_actions(); //do actions passed in $_GET like sandbox switching

		//yeah, some jQuery magic too
		$theme->include_jquery(false);

		if($core->is_plugin('wysiwyg'))
		{
			$wysiwyg = $core->load_plugin('wysiwyg');
			$wysiwyg->create_wysiwyg('blogpost_text');
		}

		$theme->js('$("div.hidden").hide(); //graceful degradation

$("h3").bind(\'click\', function (e) {
var div = $(this).next();
$(div).toggle("fast");
if($(this).html().substr(0,1) == \'+\')
{
	var length = $(this).html().length;
	$(this).html(\'-\' + $(this).html().substr(1, length - 1));
}
else
{
	var length = $(this).html().length;
	$(this).html(\'+\' + $(this).html().substr(1, length - 1));
}
});');

		if($core->is_plugin('uploadify'))
		{
			$uploadify = $core->load_plugin('uploadify');
			$theme->js('$("ul.upload_list > li > a.file_link").bind("click", function(e)
			{
				$("div.nicEdit-main").html($("div.nicEdit-main").html() + "<a href=\"" + $(this).attr(\'href\') + "\">" + $(this).html() + "</a>");
			}
			);

			$("ul.upload_list > li > a").bind("click", function(e){ e.preventDefault(); })');
		}

		// ADD NEW BLOGPOST
		echo '
<h3>-Add new article</h3>
  <div>
	<form action="" method="post">
		<table border="0">
			<tr><td>Title</td><td><input type="text" name="blogpost_title" size="98"/></td></tr>
			<tr><td>Short text for article list</td><td><textarea name="blogpost_short" rows="5" cols="83" class="blogpost"></textarea></td></tr>
			<tr><td>Article text</td><td><p>Use [code=language][/code] for syntax highlighting</p><textarea name="blogpost_text" id="blogpost_text" rows="20" cols="84" class="blogpost"></textarea>';

			if($core->is_plugin('uploadify'))
			{
				echo '<span onClick="javascript: $(\'#hidden\').toggle(\'fast\');" style="text-decoration: underline; color: #516C00; cursor: pointer;">Insert uploaded file</span><div id="hidden" style="display: none;">';
				$uploadify->print_file_list();
				echo '</div>';
			}

			echo '</td></tr>
			<tr><td>Category</td><td><select name="blogpost_category">';

		$query = mysql_query("SELECT * FROM ".DB_PREFIX."yaps_blog_category ORDER BY name ASC");
		while($cat = mysql_fetch_array($query))
		{
			echo '<option value="',$cat['id'],'">',$cat['name'],'</option>';
		}

		echo '</select></td></tr>';

		if($core->is_plugin('twitter'))
		{
			echo '<tr><td>Tweet this article?</td><td><input type="checkbox" checked="true" name="tweet_me" /></td></tr>';
		}

			echo '<tr><td colspan="2"><input type="submit" value="Post this article to sandbox" /></td></tr>
		</table>
	</form>
	<p><b>Sandbox</b> is a place, where you can view your articles <i>before</i> you publish them.</p>';

	echo '</div>';

		// ARTICLES
		echo '<h3>+Articles</h3><div class="hidden">';
		$query = mysql_query("SELECT ".DB_PREFIX."yaps_blog.id, ".DB_PREFIX."yaps_blog.title, ".DB_PREFIX."yaps_blog.sandboxed, ".DB_PREFIX."yaps_blog_category.name, ".DB_PREFIX."yaps_blog_category.id AS category_id
		FROM ".DB_PREFIX."yaps_blog
		JOIN ".DB_PREFIX."yaps_blog_category ON ".DB_PREFIX."yaps_blog.category = ".DB_PREFIX."yaps_blog_category.id
		ORDER BY ".DB_PREFIX."yaps_blog.published DESC");

		echo '<table class="nice">
		<tr><th>Title</th><th>Category</th><th>Sandbox</th><th>Options</th></tr>';
		while($article = mysql_fetch_array($query))
		{
			echo '<tr>
					<td>',$theme->icon('note.png','Article'),'<a href="',$this->generate_article_link($article['id']),'">',$article['title'],'</a></td>
					<td>',$theme->icon('bookmark_book.png','Category'),'<a href="blog-category-',$article['category_id'],'">',$article['name'],'</a></td>
					<td>',$theme->icon('arrow_refresh.png','Switch sandbox'),'<a href="admin-pluginsettings?plugin=blog&amp;action=switch_sandbox&amp;id=',$article['id'],'&amp;state=',($article['sandboxed']) ? 0 : 1,'">',($article['sandboxed']) ? 'Yes' : 'No','</a></td>
					<td><a href="',$this->generate_edit_link($article['id']),'">',$theme->icon('pencil.png','Edit'),'</a>
							<a href="',$this->generate_delete_link($article['id']),'">',$theme->icon('cancel.png','Delete'),'</a>
					</td>
					</tr>';
		}

		echo '</table></div>';

		// CATEGORIES
		echo '<h3>+Categories</h3><div class="hidden">';
		//editing grid for categories
		$datagrid = new Datagrid(DB_PREFIX.'yaps_blog_category');
		$datagrid->set_order('name','ASC');
		$datagrid->add_filter('id');
		$datagrid->draw_grid();
		echo '</div>';

	}

	/**
	 * Blog::show_article()
	 * Show article with comments and full text
	 * @return
	 */
	public function show_article()
	{
		global $core,$theme;
		if($core->is_plugin('highlight')) $hl = $core->load_plugin('highlight');

		$id = $core->router_id;

		$blog_theme = new Theme();
		$blog_theme->set_theme_file('',FILE_ARTICLE_THEME);

		$query = mysql_query("SELECT * FROM ".DB_PREFIX."yaps_blog WHERE id = ".$id);

		if(mysql_num_rows($query) > 0)
		{
			$article = mysql_fetch_array($query);
			$comments = $this->get_comments($article['id']);
			$cat = mysql_fetch_array(mysql_query("SELECT * FROM ".DB_PREFIX."yaps_blog_category WHERE id = ".$article['category']));
			$category_link = 'blog-category-'.$cat['id'].'-'.$core->encode_url($cat['name']);

			$blog_theme->purge();
			$blog_theme->assign('post_name',stripslashes($article['title']));
			$blog_theme->assign('post_text',stripslashes($article['text']));
			$blog_theme->assign('post_id',$article['id']);
			$blog_theme->assign('post_time',$article['published']);
			$blog_theme->assign('category',$cat['name']);
			$blog_theme->assign('category_link',$category_link);
			$blog_theme->assign('comments',$comments);
			$blog_theme->render();

			$theme->set_title($article['title']);

		}
		else
		{
			echo '<p>Nothing in there :)</p>';
		}
	}

	/**
	 * Blog::get_comments()
	 * Return string with formated comments according to selected theme and article id
	 * @param mixed $id
	 * @return mixed $out string with formated comments text
	 */
	private function get_comments($id)
	{
		global $core;

		$out = '';

		$query = mysql_query("SELECT * FROM ".DB_PREFIX."yaps_blog_comments WHERE article = ".$id." ORDER BY posted DESC");
		if(mysql_num_rows($query) > 0)
		{
			$theme = new Theme();
			$theme->set_theme_file('',FILE_COMMENT_THEME);

			//try to get Gravatar
			if($core->is_plugin('gravatar'))
			{
				$gravatar = $core->load_plugin('gravatar');
				$gravatar_plugin = true;
			}

			while($comment = mysql_fetch_array($query))
			{
				//do ve have gravatar and email is longer than nothing?
				if($gravatar_plugin == true && strlen($comment['email']) > 0)
				{
					$username = $gravatar->get_gravatar($comment['email'],'32').$comment['name'];
				}
				else
				{
					$username = $comment['name'];
				}

				$theme->purge();
				$theme->assign('user',$username);
				$theme->assign('posted',$core->convert_datetime($comment['posted']));
				$theme->assign('post',$comment['text']);
				$out .= $theme->get_content(); //get content of theme with assigns WITHOUT rendering it
			}
		}
		else
		{
			$out = 'No comments yet. Be the first one who comments this article.';
		}

		return $out;
	}

	/**
	 * Blog::show_category()
	 * Show articles from $core->router_id category
	 * @return
	 */
	public function show_category($all = false)
	{
		global $core;

		$id = $core->router_id; //get id from router -> id from url

		$blog_theme = new Theme();
		$blog_theme->set_theme_file('',FILE_BLOGPOST_THEME); //theme for list of blogposts

		if($all)
		{
			$query = mysql_query("SELECT * FROM ".DB_PREFIX."yaps_blog WHERE sandboxed = 0 ORDER BY published DESC LIMIT 0,5");
		}
		else
		{
			//lets get and print some info about category
			$category = mysql_fetch_array(mysql_query("SELECT * FROM ".DB_PREFIX."yaps_blog_category WHERE id = ".$id));
			echo '<h1>',$category['name'],'</h1>
			<p>',$category['description'],'</p>';

			$query = mysql_query("SELECT * FROM ".DB_PREFIX."yaps_blog WHERE category = ".$id." AND sandboxed = 0 ORDER BY published DESC");
		}

		//print articles
		if(mysql_num_rows($query) > 0)
		{
			while($article = mysql_fetch_array($query))
			{
				$link = $this->generate_article_link($article['id']);
				$comments_link = $link.'#comments';

				$cat = mysql_fetch_array(mysql_query("SELECT * FROM ".DB_PREFIX."yaps_blog_category WHERE id = ".$article['category']));
				$category_link = 'blog-category-'.$cat['id'].'-'.$core->encode_url($cat['name']); //create category link

				$count = mysql_num_rows(mysql_query("SELECT id FROM ".DB_PREFIX."yaps_blog_comments WHERE article = ".$article['id']));

				//purge theme from assigns
				$blog_theme->purge();

				//and fill it with our informations
				$blog_theme->assign('post_name',$article['title']);
				$blog_theme->assign('post_text',$article['short_text']);
				$blog_theme->assign('post_time',$core->convert_datetime($article['published']));
				$blog_theme->assign('whole_post',$link);
				$blog_theme->assign('comments_count',$count);
				$blog_theme->assign('comments_link',$comments_link);
				$blog_theme->assign('category',$cat['name']);
				$blog_theme->assign('category_link',$category_link);

				//lets go!
				$blog_theme->render();
			}
		}
		else
		{
			echo '<p>Nothing in there :)</p>';
		}
	}

	/**
	 * Blog::post_comment()
	 * Add comment to article
	 * @return
	 */
	public function post_comment()
	{
		global $core;

		$name = $core->post_hsc('name');
		$email = $core->post_hsc('email');
		$text = $core->post_hsc('comment');
		$ip = $core->get_ip();
		$article_id = $core->router_id;

		if(strlen($name) > 0 && strlen($text) > 0)
		{
			$query = mysql_query("INSERT INTO ".DB_PREFIX."yaps_blog_comments VALUES('0','".$name."','".$email."','".$text."','".$article_id."',NOW(),'".$ip."')");

			if($query)
			{
				$core->refresh($this->generate_article_link($article_id).'#comments');
			}
			else
			{
				$core->err('Error: Sorry i can`t insert your comment. Contact admin please.');
			}
		}
		else
		{
			$core->refresh($this->generate_article_link($article_id).'#comments');
		}
	}

	/**
	 * Blog::generate_article_link()
	 * Generate SEO ok link for article
	 * @param mixed $id
	 * @return
	 */
	public function generate_article_link($id)
	{
		global $core;

		$link = '';
		$query = mysql_query("SELECT * FROM ".DB_PREFIX."yaps_blog WHERE id = ".$id);
		if(mysql_num_rows($query) > 0)
		{
			$article = mysql_fetch_array($query);
			$link = 'blog-article-'.$article['id'].'-'.$core->encode_url($article['title']);
		}
		else
		{
			$core->err('Bad article id for generate_article_link function in plugin blog');
		}

		return $link;
	}

	/**
	 * Blog::generate_edit_link()
	 * Generate editation link for article
	 * @param mixed $id
	 * @return
	 */
	public function generate_edit_link($id)
	{
		return 'admin-pluginsettings?plugin=blog&amp;action=edit_article&amp;id='.$id;
	}

	/**
	 * Blog::generate_delete_link()
	 * Generate delete link for article
	 * @param mixed $id
	 * @return
	 */
	public function generate_delete_link($id)
	{
		return 'admin-pluginsettings?plugin=blog&amp;action=delete_article&amp;id='.$id;
	}

	/**
	 * Blog::rss()
	 * RSS generating function. It`s called by ./rss.php
	 * @return
	 */
	public function rss()
	{
		$query = mysql_query("SELECT * FROM ".DB_PREFIX."yaps_blog WHERE sandboxed = 0 ORDER BY id DESC");
		while($article = mysql_fetch_array($query))
		{
			echo '<item>
        <title>',$article['title'],'</title>
        <description>',$article['short_text'],'</description>
        <link>',WEB_URL,$this->generate_article_link($article['id']),'</link>
				<pubDate>',$article['published'],'</pubDate>
        </item>';
		}
	}

	/**
	 * Blog::install()
	 * Install function, create plugin tables and insert initial data
	 * @return
	 */
	public function install()
	{
		$create_table = mysql_query("CREATE TABLE IF NOT EXISTS `".DB_PREFIX."yaps_blog` (
		   `id` int(11) NOT NULL AUTO_INCREMENT,
		   `title` varchar(255) COLLATE utf8_czech_ci NOT NULL,
		   `short_text` text COLLATE utf8_czech_ci NOT NULL,
		   `text` text COLLATE utf8_czech_ci NOT NULL,
		   `category` int(11) NOT NULL,
		   `published` datetime NOT NULL,
		   `sandboxed` tinyint(1) NOT NULL DEFAULT '1',
		   PRIMARY KEY (`id`)
		   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1");

		$create_table_2 = mysql_query(" CREATE TABLE IF NOT EXISTS `".DB_PREFIX."yaps_blog_category` (
		   `id` int(11) NOT NULL AUTO_INCREMENT,
		   `name` text COLLATE utf8_czech_ci NOT NULL,
		   `description` text COLLATE utf8_czech_ci NOT NULL,
		   PRIMARY KEY (`id`)
		   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1");

		$create_table_3 = mysql_query("CREATE TABLE IF NOT EXISTS `".DB_PREFIX."yaps_blog_comments` (
		   `id` int(11) NOT NULL AUTO_INCREMENT,
		   `name` text COLLATE utf8_czech_ci NOT NULL,
		   `email` text COLLATE utf8_czech_ci NOT NULL,
		   `text` text COLLATE utf8_czech_ci NOT NULL,
		   `article` int(11) NOT NULL,
		   `posted` datetime NOT NULL,
		   `ip` varchar(15) COLLATE utf8_czech_ci NOT NULL,
		   PRIMARY KEY (`id`)
		   ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_czech_ci AUTO_INCREMENT=1");

		$insert_data = mysql_query(" INSERT INTO `".DB_PREFIX."yaps_blog` (`id`, `title`, `short_text`, `text`, `category`, `published`, `sandboxed`) VALUES
		   (1, 'Yaps! is great', 'Read about it, it`s true :)', 'Yeah, Yaps! is really great! You can find in here: <a href=\"http://yaps.mafyje.com\">http://yaps.mafyje.com</a>', 1, NOW(), 0)");

		$insert_data_2 = mysql_query("INSERT INTO `".DB_PREFIX."yaps_blog_category` (`id`, `name`, `description`) VALUES
		   (1, 'About Yaps!', 'Things about Yaps!')");

		$insert_data_3 = mysql_query("INSERT INTO `".DB_PREFIX."yaps_blog_comments` (`id`, `name`, `email`, `text`, `article`, `posted`, `ip`) VALUES
		   (1, 'Pirozek', 'pirozek@mafyje.com', 'Really cool!', 1, NOW(), '123.45.6.8')");

		$insert_data_4 = mysql_query('INSERT INTO '.DB_PREFIX.'yaps_config VALUES(\'plugin_blog_installed\',\'true\')');

		if($create_table && $create_table_2 && $create_table_3 && $insert_data && $insert_data_2 && $insert_data_3 && $insert_data_4)
		{
			return true;
		}
		else return false;
	}
}


?>